# -*- coding: utf-8 -*-
import os
import subprocess

from mon.baselib.utils import FileUtils

def run_pyinstaller(source_dir):
    try:
        if not source_dir:
            spec_path = 'main.spec'
        else:
            spec_path = os.path.join(source_dir, 'main.spec')
        result = subprocess.run(['pyinstaller', spec_path], check=True, text=True, capture_output=True)
        print("PyInstaller 执行成功:")
        print(result.stdout)
    except subprocess.CalledProcessError as e:
        print("PyInstaller 执行失败:")
        print(e.stderr)


def copy_files(source_dir, dest_dir):
    app_path = os.path.join(source_dir, 'dist', 'mon.exe')
    FileUtils.copy_file(app_path, dest_dir)


if __name__ == '__main__':
    run_pyinstaller('')
    copy_files('E:\\Maven\\My\\auto-office', 'D:\\Software\\autooffice\\mon.exe')
